package com.kgd.news.controller.admin;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.kgd.news.entity.SysMenu;
import com.kgd.news.utils.BaseController;

/**
 * @Email: huangsanm@foxmail.com
 * @Date: 2017/8/1
 * @Time: 上午11:08
 */
public class MenuController extends BaseController {

    @Override
    public void list() {
        String sql = "from sys_menu where 1 = 1 order by m_order asc";
        Page<SysMenu> data = SysMenu.dao.paginate(getPageIndex("menu"), PAGE_SIZE, "select *", sql);
        setAttr("data", data);
        render("menu_list.html");
    }

    @Override
    public void edit() {
        Integer id = getParaToInt("id");
        SysMenu dict = SysMenu.dao.findById(id);
        setAttr("menu", dict);
        render("menu_edit.html");
    }

    @Override
    public void save() {
        SysMenu us = getModel(SysMenu.class, "menu");
        if(us != null && us.getId() != null){
            us.update();
        }else{
            us.save();
        }

        list();
    }

    @Override
    public void del() {
        String ids = getPara("ids");
        Db.update("delete from sys_menu where id in (" + ids + ")");

        list();
    }


}
